from PyQt5.QtWidgets import QDialog, QVBoxLayout, QProgressBar, QApplication
from PyQt5.QtCore import Qt


class ProgressDialog(QDialog):
    """
    进度条弹窗类。
    """
    def __init__(self, title, parent=None):
        super().__init__(parent)
        self.setWindowTitle(title)
        # 设置窗口标志，移除关闭按钮和问号按钮
        self.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint & ~Qt.WindowContextHelpButtonHint)
        self.setWindowModality(Qt.WindowModal)
        self.resize(350, 120)

        # 布局
        self.layout = QVBoxLayout()

        # 进度条
        self.progress_bar = QProgressBar()
        self.layout.addWidget(self.progress_bar)

        # 设置布局
        self.setLayout(self.layout)

        self.update_progress(0)

    def update_progress(self, value):
        """
        更新进度条的值。
        """
        self.progress_bar.setValue(value)
        QApplication.processEvents()

    def update_status(self, status):
        self.close()
